//
//  MOFoodDetailView.m
//  MobileOffice
//
//  Created by 冰冰 on 2019/10/18.
//  Copyright © 2019 com.idolmedia. All rights reserved.
//

#import "MOFoodDetailView.h"

@interface MOFoodDetailView()

@property(nonatomic,strong)UIView *backView;

@property(nonatomic,strong)UILabel *foodNameLabel;

@property(nonatomic,strong)UILabel *priceLabel;

@property(nonatomic,strong)UILabel *fooderNameLabel;

@property(nonatomic,strong)UITextView *yuanLiaoTextView;

@property(nonatomic,strong)UITextView *beiZhuTextView;

@end

@implementation MOFoodDetailView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if(self) {
        
        self.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.7];
        
        UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        [button addTarget:self action:@selector(clickCancelButton) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:button];
        
        [self addSubview:self.backView];
        
    }
    return self;
}

#pragma mark -- 取消
-(void)clickCancelButton
{
    self.frame = CGRectMake(0, 0, 0, 0);
    self.backView.frame = CGRectMake(0, 0, 0, 0);
}

#pragma mark -- 确定
-(void)clickSureButton
{
    self.frame = CGRectMake(0, 0, 0, 0);
    self.backView.frame = CGRectMake(0, 0, 0, 0);
}

-(void)setModel:(MOFoodDetailModel *)model
{
    self.foodNameLabel.text = model.foodNameStr;
    
    self.priceLabel.text = model.price;
    
    self.fooderNameLabel.text = model.cook;
    
    if (model.yuanLiao.length>0) {
        self.yuanLiaoTextView.text = model.yuanLiao;
        self.yuanLiaoTextView.placeholder = @"";
    }
    
    if (model.mark.length>0) {
        self.beiZhuTextView.text = model.mark;
        self.beiZhuTextView.placeholder = @"";
    }
    
}

#pragma mark -- 懒加载
-(UIView *)backView
{
    if (!_backView) {
        _backView = [[UIView alloc]initWithFrame:CGRectMake(21, 0, SCREEN_WIDTH-42, 189)];
        _backView.centerX = SCREEN_WIDTH/2;
        _backView.centerY = SCREEN_HEIGHT/2;
        _backView.backgroundColor = [UIColor whiteColor];
        _backView.layer.masksToBounds = YES;
        _backView.layer.cornerRadius = 13.0;
        _backView.layer.borderWidth = 2;
        _backView.layer.borderColor = KGrayColor_ededed.CGColor;
        
        UILabel *tlabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 64)];
        tlabel.font = [UIFont boldSystemFontOfSize:18];
        tlabel.text = @"菜品详情";
        tlabel.centerX = _backView.width/2;
        tlabel.textAlignment = NSTextAlignmentCenter;
        [_backView addSubview:tlabel];
        
        UIButton *cancelButton = [[UIButton alloc]initWithFrame:CGRectMake(_backView.width-23-17, 0, 17, 17)];
        cancelButton.centerY = tlabel.centerY;
        [cancelButton setImage:IMAGE(@"close") forState:UIControlStateNormal];
        [cancelButton addTarget:self action:@selector(clickCancelButton) forControlEvents:UIControlEventTouchUpInside];
        [_backView addSubview:cancelButton];
        
        CGFloat mY = 0;
        NSArray *titleArray = @[@"菜品名称:",@"菜品价格:",@"菜品厨师:",@"菜品原料:"];
        CGFloat labelWidth = 67;
        for (int i = 0; i<titleArray.count; i++) {
            UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(26, tlabel.bottom + 18*(i+1) + 15*i, labelWidth, 15)];
            label.font = [UIFont boldSystemFontOfSize:14];
            tlabel.textColor = KBlackColor_2A2A2A;
            label.text = titleArray[i];
            [_backView addSubview:label];
            
            UILabel *vlaueLabel = [[UILabel alloc]initWithFrame:CGRectMake(label.right+10, label.y, _backView.width-labelWidth-52-10, 15)];
            vlaueLabel.textColor = KBlackColor_2A2A2A;
            vlaueLabel.font = FONT_SIZE(14);
            vlaueLabel.text = @"xxx";
            [_backView addSubview:vlaueLabel];
            if (i==titleArray.count-1) {
                mY = vlaueLabel.bottom;
                vlaueLabel.text = @"";
            }
            if (i==0) {
                self.foodNameLabel = vlaueLabel;
            }else if (i==1){
                self.priceLabel = vlaueLabel;
            }else if (i==2){
                self.fooderNameLabel = vlaueLabel;
            }
        }
        
        UIView *yuanLiaoView = [[UIView alloc]initWithFrame:CGRectMake(26, mY+10, _backView.width-52, 86)];
        yuanLiaoView.layer.masksToBounds = YES;
        yuanLiaoView.layer.cornerRadius = 5.5;
        yuanLiaoView.layer.borderWidth = 1;
        yuanLiaoView.layer.borderColor = KGrayColor_ededed.CGColor;
        [_backView addSubview:yuanLiaoView];
        
        self.yuanLiaoTextView = [[UITextView alloc]initWithFrame:CGRectMake(10, 10, yuanLiaoView.width-20, yuanLiaoView.height-20)];
        self.yuanLiaoTextView.placeholder = @"菜品原料描述";
        self.yuanLiaoTextView.font = FONT_SIZE(13);
        [yuanLiaoView addSubview:self.yuanLiaoTextView];
        
        UILabel *labelB = [[UILabel alloc]initWithFrame:CGRectMake(26, yuanLiaoView.bottom +20, labelWidth, 15)];
        labelB.font = [UIFont boldSystemFontOfSize:14];
        labelB.textColor = KBlackColor_2A2A2A;
        labelB.text = @"备注:";
        [_backView addSubview:labelB];
        
        UIView *beizhuView = [[UIView alloc]initWithFrame:CGRectMake(26, labelB.bottom+10, _backView.width-52, 86)];
        beizhuView.layer.masksToBounds = YES;
        beizhuView.layer.cornerRadius = 5.5;
        beizhuView.layer.borderWidth = 1;
        beizhuView.layer.borderColor = KGrayColor_ededed.CGColor;
        [_backView addSubview:beizhuView];
        
        self.beiZhuTextView = [[UITextView alloc]initWithFrame:CGRectMake(10, 10, yuanLiaoView.width-20, yuanLiaoView.height-20)];
//        self.beiZhuTextView.placeholder = @"此处输入餐厅备注内容";
        self.beiZhuTextView.font = FONT_SIZE(13);
        [beizhuView addSubview:self.beiZhuTextView];
        
        _backView.height = beizhuView.bottom + 26;
        _backView.centerY = SCREEN_HEIGHT/2;
    }
    return _backView;
}

@end
